package app

import (
	"im/args"
	"im/service"
	"im/util"
	"net/http"
)
var Contact service.ContactService

/**
添加好友接口
 */
func Addfriend(w http.ResponseWriter,r *http.Request)  {
	var arg args.ContactArg
	err := util.Bind(r,&arg)
	if nil != err {
		util.RespFail(w,err.Error())
		return
	}

	err = Contact.AddFriend(arg.Userid,arg.Dstid)

	if nil != err {
		util.RespFail(w,err.Error())
	} else {
		util.RespOK(w,arg,"成功")
	}
}

/**
好友列表接口
 */

func LoadFriend(w http.ResponseWriter, r *http.Request)  {
	var arg args.ContactArg

	err := util.Bind(r,&arg)
	if nil != err {
		util.RespFail(w,err.Error())
		return
	}
	community := Contact.SearchFriend(arg.Userid)
	util.RespOkList(w,community,len(community))
}

/**
群组列表接口
 */

func Community(w http.ResponseWriter, r *http.Request)  {
	var arg args.ContactArg

	err := util.Bind(r,&arg)
	if nil != err {
		util.RespFail(w,err.Error())
		return
	}
	community := Contact.GetLoadFriend(arg.Userid)
	util.RespOkList(w,community,len(community))
}

func JoinCommunity(w http.ResponseWriter,r *http.Request)  {
	var arg args.ContactArg
	err := util.Bind(r,&arg)
	if nil != err {
		util.RespFail(w,err.Error())
	}
}


